$(function () {
    $.post("../user/login_status", function(data) {
        if ("no" != data) {
            userId = JSON.parse(data).id;
        }
    })




})

var userId = 0;
function userlike(likeType){
    $.post("../user/login_status", function(data) {
        if ("no" != data) {
            userId = JSON.parse(data).id;
            //获取收藏对象的ID
            var likeId = $("#like").attr("value");
            $.ajax({
                "url":"../UserLikeServlet",
                "data":"likeId="+likeId+"&userId="+userId+"&likeType="+likeType,
                "type": "GET",
                "dataType":"json",
                "success": function (result){
                    if(result.data== "YES"){
                        alert("收藏成功");
                        $("#like").html("<i class='fa fa-heart' style='color:red'></i>&nbsp;&nbsp;已收藏");
                    } else if(result.data == "NO"){
                        alert("取消收藏成功");
                        $("#like").html("<i class='fa fa-heart-o'></i>&nbsp;&nbsp;收藏");
                    }else{
                        alert("操作异常，请稍后重试");
                    }

                }
            })
        } else {
            $(".login-mask,.login-table").show();
        }
    })

}